import NET from '@/utils/request.js'
import API from '@/config/api.js'

export default {
  data() {
    return {
			IMG_URL: API.IMG_URL,
			def_avatar_img: require('@/static/img/tabbar/me.png'),
			sheep_img: require('@/static/img/sheep.jpg'),
			cattle_img: require('@/static/img/cattle.jpg'),
			
      windowHeight: 0,
			currentTime: null,
			commentList: [],
			share:{
				title: '',
				path: '@/pages/video/vedio/',
				imageUrl: '',  //图片链接，必须是网络连接，后面拼接时间戳防止本地缓存,
				desc: '',
				content: ''
			}
    };
  },
	
	onShareAppMessage(res) {
		return {
			title: this.share.title,
			path: this.share.path,
			imageUrl: this.share.imageUrl,
			desc: this.share.desc,
			content: this.share.content,
		}
	},
	
	onShow() {
		this.getSystemHeight()
	},
	
  methods: {		
		// 获取设备高度
		getSystemHeight() {
			uni.getSystemInfo({
				success: res => {
					this.windowHeight = res.windowHeight
				}
			})
		},
		
		// 获取 Storage 中的 user
		getStorageUser() {
			return uni.getStorageSync('user')
		},
		
		// 获取 Storage 中的 token
		getStorageToken() {
			return uni.getStorageSync('token')
		},
		
		// 判断 token
		judgeToken() {
			if (!this.getStorageToken()) {
				uni.showToast({
					title: '请登录',
					icon: 'error'
				})
				
				setTimeout(() => {
					uni.switchTab({
						url: '/pages/mine/mine'
					})
				}, 500)
				return false
			} else {
				return true
			}
		},
		
		// 调用转发
		onShareAppMessage(e){
			console.log(e, '转发了');
			
			uni.showToast({
				title: '已转发！',
				icon: 'success'
			})
		},
		
		// 获取当前时间
		getCurrentTime(){
			var date = new Date(),
			year = date.getFullYear(),
			month = date.getMonth() + 1,
			day = date.getDate(),
			hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
			minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
			second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
			month >= 1 && month <= 9 ? (month = "0" + month) : "";
			day >= 0 && day <= 9 ? (day = "0" + day) : "";
			var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
			this.currentTime = timer
		},
		
		// 格式化 视频是几天前发布的
		formatCreateTime(time){  // time 的值为 毫秒
			if (time) {
				// var startDate = time.replace(new RegExp("-","gm"),"/");
				// var startDateM = (new Date(startDate)).getTime(); //得到毫秒数
				
				var minute = 1000 * 60;      //把分，时，天，周，半个月，一个月用毫秒表示
				var hour = minute * 60;
				var day = hour * 24;
				var week = day * 7;
				var halfamonth = day * 15;
				var month = day * 30;
				
				var now = new Date().getTime();   //获取当前时间毫秒
				// var diffValue = now - startDateM;//时间差
				var diffValue = now - time;//时间差
					
				if (diffValue < 0) {
					return;
				}
				
				var minC = diffValue/minute;  //计算时间差的分，时，天，周，月
				var hourC = diffValue/hour;
				var dayC = diffValue/day;
				var weekC = diffValue/week;
				var monthC = diffValue/month;
				
				var result = ''
				
				if (monthC >= 1 && monthC < 4) {
					result = " " + parseInt(monthC) + " ᠰᠠᠷ᠎ᠠ᠎ᠶᠢᠨ ᠡᠮᠦᠨ᠎ᠡ"
				} else if(weekC >= 1 && weekC < 4) {
					result = " " + parseInt(weekC) + " ᠭᠠᠷᠠᠭ᠎ᠤᠨ ᠡᠮᠦᠨ᠎ᠡ"
				} else if(dayC >= 1 && dayC < 7) {
					result = " " + parseInt(dayC) + " ᠡᠳᠦᠷ᠎ᠦᠨ ᠡᠮᠦᠨ᠎ᠡ"
				} else if (hourC >= 1 && hourC < 24) {
					result = " " + parseInt(hourC) + " ᠴᠠᠭ᠎ᠤᠨ ᠡᠮᠦᠨ᠎ᠡ"
				} else if (minC >= 1 && minC < 60) {
					result = " " + parseInt(minC) + " ᠮᠢᠨᠦ᠋ᠲ᠎ᠦᠨ ᠡᠮᠦᠨ᠎ᠡ"
				} else {
					result = " " + 0 + " ᠮᠢᠨᠦ᠋ᠲ᠎ᠦᠨ ᠡᠮᠦᠨ᠎ᠡ"
					// var datetime = new Date();
					// datetime.setTime(time);
					// var Nyear = datetime.getFullYear();
					// var Nmonth = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
					// var Ndate = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
					// var Nhour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
					// var Nminute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
					// var Nsecond = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
					// result = Nyear + "-" + Nmonth + "-" + Ndate
				}
				return result;
			}
		},
		
		// 格式化蒙文
		formatMon1(val) {
			return val.replace(/\u180E/g, '')
		},
		
		formatMon2(val) {
			return val.replace('᠃', '')
		},
		
		// 格式化牲畜的名称
		formatAnimalMonName(val) {
			if (val == 'ximentaer') {
				return 'ᠱᠢᠮᠧᠨ᠋ᠳᠡᠷ'
			}
		},
		
		// 格式化牲畜性别
		formatSex(val) {
			if (val == 0) {
				return 'ᠡᠷ᠎ᠡ'
			} else {
				return 'ᠡᠮ᠎ᠡ'
			}
		},
		
		// 格式化开关的名称
		formatKaiGuanMonName(val) {
			if (val == 'shui') {
				return 'ᠲᠣᠭᠲᠠᠮᠠᠯ ᠳᠤᠯᠠᠭᠠᠨᠲᠤ ᠤᠰᠤᠯᠠᠯᠲᠠ'
			} else if (val == 'siwei') {
				return 'ᠲᠡᠵᠢᠭᠡᠬᠦ'
			} else if (val == 'xiaosha') {
				return 'ᠠᠷᠢᠭᠤᠳᠭᠠᠬᠤ'
			} else if (val == 'qingli') {
				return 'ᠴᠡᠪᠡᠷᠯᠡᠬᠦ'
			} 
		},
		
		// 获取 评论列表
		getCommentListByBlogId(id) {
			NET.request(API.getCommentListByBlogId, { blogId: id }, 'GET')
			.then(res => {
				if (res.code == 200) {
					this.commentList = res.data
				}
			})
			.catch(err => {
				console.error('评论信息获取失败！', err)
			})
		},
		
  }
};
